package com.ld.wms.business.material.controller;


import com.ld.wms.business.material.service.FieldInfoService;
import com.ld.wms.business.material.vo.req.FieldInfoReqVo;
import com.ld.wms.business.material.vo.resp.FieldInfoRespVo;
import com.ld.wms.business.material.vo.resp.SupplierRespVo;
import com.ld.wms.common.ResultResponse;
import com.ld.wms.common.vo.GenerateListVo;
import com.ld.wms.common.vo.GeneratePageListVo;
import com.ld.wms.common.vo.PrimaryKeyReqVo;
import com.ld.wms.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自定义字段表 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2025-02-26
 */
@Slf4j
@Tag(name = "试剂字段定义相关接口")
@RestController
public class FieldInfoController {

    @Autowired
    private FieldInfoService fieldInfoService;

    @GetMapping("/api/wms/fieldInfo/getPageList")
    @Operation(summary = "所有字段列表(查询所有size传9999)")
    public ResultResponse<GeneratePageListVo<FieldInfoRespVo>> getPageList(
            @RequestParam(required = false) String name,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ) {
        GeneratePageListVo<FieldInfoRespVo> allList = fieldInfoService.getPageList(name, current, size);
        return ResultResponse.success(allList);
    }

    @GetMapping("/api/wms/fieldInfo/getById")
    @Operation(summary = "查询字段详情")
    public ResultResponse<FieldInfoRespVo> getById(
            @RequestParam Long id
    ) {
        FieldInfoRespVo fieldInfoRespVo = fieldInfoService.getById(id);
        return ResultResponse.success(fieldInfoRespVo);
    }

    @PostMapping("/api/wms/fieldInfo/add")
    @Operation(summary = "添加")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody FieldInfoReqVo reqVo
    ) {
        fieldInfoService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/wms/fieldInfo/update")
    @Operation(summary = "修改")
    public ResultResponse<ResultResponseEnum> update(
            @RequestBody FieldInfoReqVo reqVo
    ) {
        fieldInfoService.updateById(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/wms/fieldInfo/delete")
    @Operation(summary = "删除")
    public ResultResponse<ResultResponseEnum> deleteById(
            @RequestBody PrimaryKeyReqVo reqVo
    ) {
        fieldInfoService.deleteById(reqVo.getId());
        return ResultResponse.success();
    }

}

